<?php
namespace app\backend\validate;
use app\common\RootValidate;

class AdminValidate extends RootValidate
{
    protected $rule = [
        'id' => 'require|number',
        'state' => 'require|number',
        'adminName' => 'require',
        'password' => 'require|length:6,16',
        'repeatPassword' => 'require|confirm:password',
        'passwd' => 'length:6,16',
        'rePwd' => 'confirm:passwd',
        'oldPassword' => 'require|different:password',
        'realName' => 'require|chs',
        'mobile' => 'regex:^1[3,4,5,6,7,8,9]\d{9}$',
        'email' => 'email',
        'imgCode'  => 'require',
        'imgKey'   => 'require',
        'roleId'   => 'require',
    ];

    protected $message = [
        'id.require' => '账号不存在',
        'id.number' => '无效的账号',
        'state.require' => '请选择用户状态',
        'state.number' => '用户状态无效',
        'adminName.require' => '请输入用户名',
        'password.require' => '请输入密码',
        'password.length' => '密码长度为6-16位',
        'repeatPassword.require' => '确认密码不能为空',
        'repeatPassword.confirm' => '确认密码和登录密码不一致',
        'passwd.length' => '密码长度为6-16位',
        'rePwd.confirm' => '确认密码和登录密码不一致',
        'oldPassword.require' => '原密码不能为空',
        'oldPassword.different' => '原密码和新密码不能相同',
        'realName.require' => '请填写您的真实姓名',
        'realName.chs' => '真实姓名不合法',
        'mobile.regex' => '无效的手机号码',
        'email.email' => '电子邮箱格式不正确',
        'imgCode.require'  => '请输入验证码',
        'imgKey.require'   => '请刷新验证码',
        'roleId.require'  => '请选择角色',
    ];

    protected $scene = [
        'add' => ['roleId', 'state', 'realName', 'adminName', 'password', 'repeatPassword', 'mobile', 'email'],
        'edit'  =>  ['id', 'state', 'roleId', 'realName', 'passwd', 'rePwd', 'mobile', 'email'],
        'login' => ['adminName', 'password', 'imgCode', 'imgKey'],
        'modify' => ['realName', 'mobile', 'email'],
        'resetPwd' => ['password', 'repeatPassword', 'oldPassword'],
    ];
}